<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <script>
             var p1={
            name:'Trump',
            age:76,
            gender:'男',
            address:{
                contry:"美国"
            },
            vote:function()
            {
                console.log(this.name+'得了216票');
            }
        }
        function deepcopy(obj)
        {
            var newobj={}
            for(var i in obj)
            {
                var prop=obj[i]   //拿出obj对象的属性值
                if(prop instanceof Object)  //如果属性的值是对象，那么就递归复制    instanceof属于
                {
                    newobj[i]=deepcopy(prop)
                }else if(prop instanceof Array)  //数组也是复杂数据类型，是的话就递归复制
                {
                    newobj[i]=deepcopy(prop)
                }else{
                    newobj[i]=prop  //不是数组和对象的话就直接复制对象属性的值
                }
                
            }
            return newobj;
        }
        var p3=deepcopy(p1)
        p3.name='普京'
        p3.address.contry='中国'
        console.log('p1==>',p1.name,'p3==>',p3.name);
        console.log('p1==>',p1.address.contry,'p3==>',p3.address.contry);

    </script>
</body>
</html>